/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.merak.core.web.mvc.validation;

import javax.servlet.ServletException;

import org.merak.core.web.HttpRequest;
import org.merak.core.web.HttpResponse;

public abstract class BatchValidator {

	//~ Attributes ///////////////////////////////////////////////////////////////
	//****************************************************************************
	private TemplateParameter[] parameters = null;
	private String              view       = null;

	//~ Constructors /////////////////////////////////////////////////////////////
	//****************************************************************************
	public BatchValidator(String[] parameters,String view) {

		// Attributes
		this.view       = view;
		this.parameters = new TemplateParameter[parameters.length];

		// Parse parameters
		for (int i=0; i<parameters.length; i++) {
			this.parameters[i] = new TemplateParameter(parameters[i]);
		}

	}

	//~ Methods //////////////////////////////////////////////////////////////////
	//****************************************************************************
	/** Performs a validation */
	public abstract boolean validate(HttpRequest request,HttpResponse response)
			throws ServletException;

	//****************************************************************************
	/** The view to redirect the user when the validation fails */
	public String getView() {
		return this.view;
	}
	//****************************************************************************
	/** Returns the set of templates used to validate parameters */
	protected final TemplateParameter[] getParameters() {
		return this.parameters;
	}
	//****************************************************************************
}
